from django.db import models
import hashlib

class User(models.Model):
    GENDER_CHIOCES = (
        (0,'女'),
        (1,'男')
    )

    phone = models.CharField(max_length=11,null=True,blank=True,unique=True,verbose_name='手机号')
    _password = models.CharField(max_length=128,null=True,blank=True,verbose_name='真实密码')
    password = models.CharField(max_length=128,null=True,blank=True,verbose_name='密码')
    nickname = models.CharField(max_length=32,null=True,blank=True,verbose_name='昵称')
    gender = models.IntegerField(choices=GENDER_CHIOCES,default=1,null=True,blank=True,verbose_name='性别')
    job_title = models.CharField(null=True,blank=True,max_length=32,verbose_name='职称')
    introduction = models.CharField(null=True,blank=True,max_length=256,verbose_name='简介')
    avatar = models.CharField(null=True,blank=True,max_length=256,verbose_name='头像')

    create_at = models.DateTimeField(auto_now_add=True,verbose_name='创建时间')
    update_at = models.DateTimeField(auto_now=True,verbose_name = '修改时间')

    class Meta:
        db_table = 't_user'

    @property
    def password(self):
        return self._password
    
    @password.setter
    def password(self,pwd):
        #数据加密
        self._password = hashlib.md5(pwd.encode('utf-8')).hexdigest()

    #输入的密码raw_pwd
    def check_password(self,raw_pwd):
        pwd = hashlib.md5(raw_pwd.encode('utf-8')).hexdigest()
        return pwd == self._password

from django.db import models


from course_app.models import Stage
from teacher_app.models import Teacher


# Create your models here.
class FreeCourse(models.Model):
    price = models.IntegerField(blank=True, null=True,verbose_name='价格')
    img = models.CharField(blank=True,null=True,max_length=512,verbose_name='图片')

    start_time = models.DateTimeField(blank=True,null=True,verbose_name='开始时间')
    end_time = models.DateTimeField(blank=True,null=True,verbose_name='结束时间')


    stage = models.ForeignKey(Stage,related_name='free_courses',on_delete=models.CASCADE,verbose_name='课程阶段',null=True,blank=True)
    teacher = models.ForeignKey(Teacher,related_name='free_courses',on_delete=models.CASCADE,verbose_name='讲师',null=True,blank=True)

    class Meta:
        db_table = 't_free_course'
